﻿
$(function () {
    //初始化列表信息
    init();
});

//初始化列表信息
function init(queryData) {
    $('#list').datagrid({
        title: '会议室管理',
        idField: 'MeetingRoomID',
        fitColumns: 'true',
        singleSelect: true,
        autoRowHeight: true,
        nowrap: true,
        striped: true,
        pagination: true,
        url: '/MeetingRoom/GetList',
        columns: [[
			{ field: 'ck', checkbox: true },
			{ field: 'MeetingRoomID', title: 'ID', hidden: true},
			{ field: 'MeetingRoomName', title: '会议室名称', width: 180},
			{ field: 'Address', title: '会议室地址', width: 180},
			{ field: 'Area', title: '会议室面积', width: 180},
			{ field: 'TelephoneNumber', title: '会议室电话', width: 180},
			{ field: 'Capacity', title: '容纳人数', width: 180},
			{
			    field: 'HaveTelephone', title: '是否有电话', width: 180,
			    formatter: function (value, row, index) {
			        if (value == true) {
			            return "有";
			        }
			        if (value == false) {
			            return "无";
			        }
			    }
			},
			{
			    field: 'HaveInternet', title: '是否有网络', width: 180,
			    formatter: function (value, row, index) {
			        if (value == true) {
			            return "有";
			        }
			        if (value == false) {
			            return "无";
			        }
			    }
			},
			{
			    field: 'HaveProjector', title: '是否有投影', width: 180,
			    formatter: function (value, row, index) {
			        if (value == true) {
			            return "有";
			        }
			        if (value == false) {
			            return "无";
			        }
			    }
			},
			{
			    field: 'HaveVideoMeeting', title: '是否有视频会议', width: 180,
			    formatter: function (value, row, index) {
			        if (value == true) {
			            return "有";
			        }
			        if (value == false) {
			            return "无";
			        }
			    }
			},
			{ field: 'Remarks', title: '备注', width: 180, hidden: true },
			{
			    field: 'Status', title: '状态', width: 180,
			    formatter: function (value, row, index) {
			        if (value == 0) {
			            return "停用";
			        }
			        if (value == 1) {
			            return "正常";
			        }
			    }
			},
			{ field: 'CreateBy', title: '创建人', width: 180, hidden: true },
			{ field: 'CreateTime', title: '创建时间', width: 180, hidden: true },
			{ field: 'UpdateBy', title: '修改人', width: 180, hidden: true },
			{ field: 'UpdateTime', title: '修改时间', width: 180, hidden: true },
		
        ]],
    });
}

//弹出增加窗口
function add() {
    //formClear();
    $('#dlg').dialog('open').dialog('setTitle', '增加');
    $('#fm').form('clear');//这样会导致@Html.CheckBoxFor(m => m.HaveProjector)它的值为null 无法通验证
    $('#Status').combobox('setValue', 1);//设置状态默认值为正常
    url = '/MeetingRoom/Create';
}

//弹出修改窗口
function edit() {
    var row = $('#list').datagrid('getSelected');
    if (row) {
        $('#dlg').dialog('open').dialog('setTitle', '修改');
        $('#fm').form('load', row);
        url = '/MeetingRoom/Edit';
    }
}

function formClear() {
    $("#Remarks").val("");
    $("#Capacity").val("");
    $("#TelephoneNumber").val("");
    $("#Area").val("");
    $("#Address").val("");
    $("#MeetingRoomName").val("");
    $("#MeetingRoomID").val("");
    $("#HaveProjector option:checked").val("checked");
}

//保存数据
function save() {
    $('#fm').form('submit', {
        url: url,
        onSubmit: function () {
            return $(this).form('validate');
        },
        success: function (result) {
            if (result == 'OK') {
                $('#dlg').dialog('close');      // close the dialog  
                $('#list').datagrid('reload');    // reload the user data  
            } else {
                $.messager.show({
                    title: 'Error',
                    msg: result
                });
            }
        }
    });
}

//删除
function del() {
    var rows = $('#list').datagrid('getSelected');
    if (rows) {
        $.messager.confirm(delDlgTitle, delDlgMsg, function (r) {
            if (r) {
                $.post('/MeetingRoom/Delete', { id: rows.MeetingRoomID },
                    function (result) {
                        if (result == 'OK') {
                            $("#list").datagrid('clearSelections');
                            $('#list').datagrid('reload');    // reload the user data  
                        } else {
                            $.messager.show({   // show error message  
                                title: 'Error',
                                msg: result
                            });
                        }
                    });
            }
        });
    }
}